package likouJava;

public class 两两交换链表中的节点 {
    public ListNode swapPairs(ListNode head) {
        if(head == null){
            return null;
        }
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode cur = dummy;

        while (cur.next != null && cur.next.next != null) {
            ListNode left = cur.next;
            ListNode right = cur.next.next;

            //交换
            left.next = right.next;
            right.next = left;
            cur.next = right;

            cur = left;
        }
        return dummy.next;
    }

}
